package Context;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Properties;

@WebServlet(name = "Context.ServletContextTest04", value = "/Context.ServletContextTest04")
public class ServletContextTest04 extends HttpServlet {

    protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        ServletConfig config = this.getServletConfig();
        ServletContext servletContext = config.getServletContext();
        InputStream io =  servletContext.getResourceAsStream("/WEB-INF/itcast.properties");
        Properties pro = new Properties();
        pro.load(io);
        out.write("CompanyName="+pro.getProperty("CompanyName"));
        out.write("  Address="+pro.getProperty("Address"));
    }

    protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

}